//
//  JourneyTableViewCell.m
//  FreeTrip
//
//  Created by 352324497@qq.com on 15/11/25.
//  Copyright © 2015年 邓芮. All rights reserved.
//

#import "JourneyTableViewCell.h"

@implementation JourneyTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = NO;
        CGFloat width = KScreenWidth - 10 * KScreenWidth / 375 * 2;
        CGFloat height = width / 630 * 330;
        self.backgroundImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10 * KScreenWidth / 375, 10 * KScreenWidth / 375, width, height)];
        [self.contentView addSubview:_backgroundImageView];
        
        UIView *coverView = [[UIView alloc]initWithFrame:self.backgroundImageView.frame];
        coverView.backgroundColor = [UIColor blackColor];
        coverView.alpha = 0.2;
        [self.contentView addSubview:coverView];
        
        CGFloat x = 30 * KScreenWidth / 375;
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, height / 7 * 5, KScreenWidth - x * 2, height / 7)];
        self.nameLabel.textColor = [UIColor whiteColor];
        self.nameLabel.font = [UIFont boldSystemFontOfSize:18 * KScreenWidth / 375];
        [self.contentView addSubview:_nameLabel];
        
        self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, height / 7 * 6, KScreenWidth - x * 2, height / 7)];
        self.timeLabel.textColor = [UIColor whiteColor];
        self.timeLabel.font = [UIFont systemFontOfSize:16 * KScreenWidth / 375];
        [self.contentView addSubview:_timeLabel];
        
        
        self.myDescriptionLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, height + 10 * KScreenWidth / 375, KScreenWidth - x * 2, 10)];
        self.myDescriptionLabel.numberOfLines = 0;
//        self.myDescriptionLabel.textColor = [UIColor grayColor];
        self.myDescriptionLabel.font = [UIFont systemFontOfSize:16 * KScreenWidth / 375];
        [self.contentView addSubview:_myDescriptionLabel];
    }
    return self;
}
-(void)setModel:(BookJourneyModel *)model
{
    
    CGFloat width = KScreenWidth - 10 * KScreenWidth / 375 * 2;
    CGFloat height = width / 630 * 330;
    CGFloat x = 30 * KScreenWidth / 375;
    _model = model;
    [self.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.nameLabel.text = model.name;
    self.timeLabel.text = [NSString stringWithFormat:@"%ld天 / %ld个旅行地", (long)model.plan_days_count, (long)model.plan_nodes_count];
    self.myDescriptionLabel.text = model.myDescription;
    CGRect bounds = [model.myDescription boundingRectWithSize:CGSizeMake(KScreenWidth - x * 2, 100) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16 * KScreenWidth / 375] forKey:NSFontAttributeName] context:nil];
    self.myDescriptionLabel.frame = CGRectMake(x, height + 10 * KScreenWidth / 375 * 2, KScreenWidth - x * 2, bounds.size.height);
}

+(CGFloat)heightForCell:(BookJourneyModel *)model
{
    CGFloat width = KScreenWidth - 10 * KScreenWidth / 375 * 2;
    CGFloat height = width / 630 * 330;
    CGFloat x = 30 * KScreenWidth / 375;
    CGRect bounds = [model.myDescription boundingRectWithSize:CGSizeMake(KScreenWidth - x * 2, 100) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16 * KScreenWidth / 375] forKey:NSFontAttributeName] context:nil];
    return height + bounds.size.height + x
    ;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
